class Solution(object):
    def imageSmoother(self, img):
        """
        :type img: List[List[int]]
        :rtype: List[List[int]]
        """
        m = len(img)
        n = len(img[0])
        out = [[0 for _ in range(n)] for _ in range(m)]
        for i in range(m):
            for j in range(n):
                total = 0
                count = 0
                for k in range(-1, 2):
                    for t in range(-1, 2):
                        if 0 <= i + k < m and 0 <= j + t < n:
                            total += img[i + k][j + t]
                            count += 1
                out[i][j] = total // count
        return out